package com.liner;

import java.util.Random;
import java.util.Scanner;

public class Guessing {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random rand = new Random();

        System.out.println("欢迎来到猜一猜");
        System.out.println("系统随机数字中...");
        int random = rand.nextInt(100);
       /* do {
            System.out.print("请输入所猜数字:");
            int num = scanner.nextInt();
            if (num == random) {
                System.out.println("恭喜你猜对了");
                break;
            } else if (num > random) {
                System.out.println("猜大了");
            } else {
                System.out.println("猜小了");
            }
        } while (true);
        */

        int count = 10;
        while(true){
            System.out.print("请输入所猜数字(您只有10次机会):");
            int num = scanner.nextInt();
            if (num == random) {
                System.out.println("恭喜你猜对了");
                count--;
                System.out.println("本次作答使用机会" + (10-count) + "次");
                break;
            } else if (num > random) {
                System.out.println("猜大了");
                count--;
                System.out.println("还剩"+ count + "次机会");
            } else {
                System.out.println("猜小了");
                count--;
                System.out.println("还剩"+ count + "次机会");
            }
            if (count == 0) {
                System.out.println("机会用尽，请下次再来");
                break;
            }

        }

    }
}
